

package com.hazelcast.client.impl.protocol.task.multimap;

import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.task.AbstractPartitionMessageTask;
import com.hazelcast.function.ConsumerEx;
import com.hazelcast.instance.impl.Node;
import com.hazelcast.internal.monitor.impl.LocalMultiMapStatsImpl;
import com.hazelcast.internal.nio.Connection;
import com.hazelcast.multimap.impl.MultiMapContainer;
import com.hazelcast.multimap.impl.MultiMapService;

public abstract class AbstractMultiMapPartitionMessageTask<P> extends AbstractPartitionMessageTask<P> {


    protected AbstractMultiMapPartitionMessageTask(ClientMessage clientMessage, Node node, Connection connection) {
        super(clientMessage, node, connection);
    }

    @Override
    public String getServiceName() {
        return MultiMapService.SERVICE_NAME;
    }

    protected void updateStats(ConsumerEx<LocalMultiMapStatsImpl> statsUpdaterFn) {
        if (getContainer().getConfig().isStatisticsEnabled()) {
            statsUpdaterFn.accept(((MultiMapService) getService(MultiMapService.SERVICE_NAME)).getLocalMultiMapStatsImpl(getDistributedObjectName()));
        }
    }

    protected MultiMapContainer getContainer() {
        MultiMapService service = getService(MultiMapService.SERVICE_NAME);
        return service.getOrCreateCollectionContainer(getPartitionId(), getDistributedObjectName());
    }

    @Override
    protected String getUserCodeNamespace() {
        return MultiMapService.lookupNamespace(nodeEngine, getDistributedObjectName());
    }
}
